package cn.lds.healthj377.service.impl;

import cn.lds.healthj377.domain.HealthExamItem;
import cn.lds.healthj377.dto.DsHealthConstant;
import cn.lds.healthj377.dto.ResponseDTO;
import cn.lds.healthj377.exception.SysException;
import cn.lds.healthj377.mapper.HealthExamItemMapper;
import cn.lds.healthj377.service.HealthExamItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class HealthExamItemServieImpl implements HealthExamItemService {

    @Autowired
    private HealthExamItemMapper healthExamItemMapper;


    @Override
    public ResponseDTO<List<HealthExamItem>> selectHealthExamItemAll() {

        List<HealthExamItem> healthExamItems = healthExamItemMapper.selectHealthExamItemAll();
        if (CollectionUtils.isEmpty(healthExamItems)){
            return ResponseDTO.buildError(DsHealthConstant.SysMsg.QUERY_FAIL);
        }

        return ResponseDTO.buildSuccess(healthExamItems);
    }

    @Override
    public ResponseDTO addHealthExamItem(HealthExamItem healthExamItem) throws SysException {

        int i = healthExamItemMapper.addHealthExamItem(healthExamItem);
        if (i <=0){
            throw new SysException(ResponseDTO.buildError(DsHealthConstant.SysMsg.ADD_ERR));
        }

        return ResponseDTO.buildSuccess();
    }
}
